package com.zzy.demo.web;

import java.util.Date;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
/**
 * 
 * @author guokaige
 *
 */
@Controller
public class HelloController {

	@RequestMapping("/")
	@ResponseBody
	public String hello() {
		//取得根目录路径  
	     String rootPath=getClass().getResource("/").getFile().toString();
		return "hello cloud:"+rootPath;
	}

	@RequestMapping("/index")
	public String index(Model model) {
		model.addAttribute("hello", "12321321");
		return "index";
	}
	
	@RequestMapping("/hello")
    public String welcome(ModelMap model) {
        model.put("time", new Date());
        model.put("message", "你好吗??");
        return "hello";
    }

	
	
	

	@RequestMapping("/login")
	public String login(Model model) {
		return "login";
	}
	
	
	
	@RequestMapping("/loginAction")
	public String login(HttpServletRequest request, HttpServletResponse response, Model model) {
		String userName = request.getParameter("username");
		String password = request.getParameter("password");
		System.out.println(userName+"---------------"+password);
		request.getSession().setAttribute("user", userName);
		return "index";

	}

	@RequestMapping("/loginOut")
	public String loginOut(HttpServletRequest request, HttpServletResponse response, Model model) {
		
		request.getSession().removeAttribute("user");
		return "login";

	}
	
}
